package com.insea.model;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;

@Entity
public class Patient extends BaseObject{

	private Long id;
	private String numPat;
	private String nomPat;
	private String prenomPat;
	private String cinPat;
	private String adressePat;
	private String numSecPat;
	private CategoriePat categoriePatient;
	
	
	@Id
    @GeneratedValue(strategy = GenerationType.AUTO)
	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}
	
	@Column(name = "numPat", nullable=false, unique=true)
	public String getNumPat() {
		return this.numPat;
	}

	public void setNumPat(String numPat) {
		this.numPat = numPat;
	}

	@Column(name = "nomPat")
	public String getNomPat() {
		return this.nomPat;
	}

	public void setNomPat(String nomPat) {
		this.nomPat = nomPat;
	}

	@Column(name = "prenomPat")
	public String getPrenomPat() {
		return this.prenomPat;
	}

	public void setPrenomPat(String prenomPat) {
		this.prenomPat = prenomPat;
	}

	@Column(name = "cinPat")
	public String getCinPat() {
		return this.cinPat;
	}

	public void setCinPat(String cinPat) {
		this.cinPat = cinPat;
	}

	@Column(name = "adressePat")
	public String getAdressePat() {
		return this.adressePat;
	}

	public void setAdressePat(String adressePat) {
		this.adressePat = adressePat;
	}

	@Column(name = "numSecPat")
	public String getNumSecPat() {
		return this.numSecPat;
	}

	public void setNumSecPat(String numSecPat) {
		this.numSecPat = numSecPat;
	}

	@ManyToOne
    @JoinColumn(name="CATEGORIE_PATIENT_ID")
	public CategoriePat getCategoriePatient() {
		return categoriePatient;
	}

	public void setCategoriePatient(CategoriePat categoriePatient) {
		this.categoriePatient = categoriePatient;
	}

	public boolean equals(Object other) {
		if ((this == other))
			return true;
		if ((other == null))
			return false;
		if (!(other instanceof  Patient))
			return false;
		 Patient castOther = ( Patient) other;

		return ((this.getNumPat() == castOther.getNumPat()) || (this
				.getNumPat() != null && castOther.getNumPat() != null && this
				.getNumPat().equals(castOther.getNumPat())))
				&& ((this.getNomPat() == castOther.getNomPat()) || (this
						.getNomPat() != null && castOther.getNomPat() != null && this
						.getNomPat().equals(castOther.getNomPat())))
				&& ((this.getPrenomPat() == castOther.getPrenomPat()) || (this
						.getPrenomPat() != null
						&& castOther.getPrenomPat() != null && this
						.getPrenomPat().equals(castOther.getPrenomPat())))
				&& ((this.getCinPat() == castOther.getCinPat()) || (this
						.getCinPat() != null && castOther.getCinPat() != null && this
						.getCinPat().equals(castOther.getCinPat())))
				&& ((this.getAdressePat() == castOther.getAdressePat()) || (this
						.getAdressePat() != null
						&& castOther.getAdressePat() != null && this
						.getAdressePat().equals(castOther.getAdressePat())))
				&& ((this.getNumSecPat() == castOther.getNumSecPat()) || (this
						.getNumSecPat() != null
						&& castOther.getNumSecPat() != null && this
						.getNumSecPat().equals(castOther.getNumSecPat())));
	}

	public int hashCode() {
		int result = 17;

		result = 37 * result
				+ (getNumPat() == null ? 0 : this.getNumPat().hashCode());
		result = 37 * result
				+ (getNomPat() == null ? 0 : this.getNomPat().hashCode());
		result = 37 * result
				+ (getPrenomPat() == null ? 0 : this.getPrenomPat().hashCode());
		result = 37 * result
				+ (getCinPat() == null ? 0 : this.getCinPat().hashCode());
		result = 37
				* result
				+ (getAdressePat() == null ? 0 : this.getAdressePat()
						.hashCode());
		result = 37 * result
				+ (getNumSecPat() == null ? 0 : this.getNumSecPat().hashCode());
		return result;
	}

	@Override
	public String toString() {
		return this.numPat;
	}
}
